import 'package:bilibili/http/dao/login_dao.dart';

enum HttpMethod { GET, POST, PUT, DELETE }

/// 基础请求
abstract class BaseRequest {
  var pathParams;
  var useHttps = true;

  String baseUrl() {
    return "api.devio.org";
  }

  HttpMethod httpMethod();

  String path();

  String url() {
    Uri uri;
    var pathString = path();
    if (pathParams != null) {
      if (path().endsWith("/")) {
        pathString = "${path()}$pathParams";
      } else {
        pathString = "${path()}/$pathParams";
      }
    }

    if (useHttps) {
      uri = Uri.https(baseUrl(), pathString, params);
    } else {
      uri = Uri.http(baseUrl(), pathString, params);
    }

    if (needLogin()) {
      addHeader('boarding-pass', LoginDao.getBoardingPass());
    }

    print("url:${uri.toString()}");
    print("headers:$header");

    return uri.toString();
  }

  bool needLogin();

  Map<String, String> params = Map();

  /// 添加参数
  BaseRequest add(String key, Object value) {
    params[key] = value.toString();
    return this;
  }

  Map<String, dynamic> header = {
    'course-flag': 'fa',
    'auth-token': 'ZmEtMjAyMS0wNC0xMiAyMToyMjoyMC1mYQ==fa'
  };

  /// 添加header
  BaseRequest addHeader(String key, Object value) {
    header[key] = value.toString();
    return this;
  }
}
